package com.version1.diabeco.data;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;

public class ApplicationDaoImpl extends AbstractDao {

	private static ApplicationDaoImpl instance;

	protected ApplicationDaoImpl(Context context) {
		super(context);
	}

	/**
	 * Retrieves the singleton instance. Receives a context which is used for database initialization but also stored
	 * for subsequent sql operation calls.
	 * 
	 * This method is thread-safe.
	 * 
	 * @return ApplicationDaoImpl with the instance.
	 */
	public static synchronized ApplicationDaoImpl getInstance(Context context) {
		if (instance == null) {
			instance = new ApplicationDaoImpl(context);
		}

		instance.setContext(context);

		return instance;
	}

	public void truncate() {
		SQLiteDatabase db = this.getWritableDatabase();
		this.truncateTables(db);
	}

	public void addFixedData() {
		SQLiteDatabase db = this.getWritableDatabase();
		this.addFixedData(db);
	}

	public void showComida() {
		SQLiteDatabase db = this.getReadableDatabase();
		this.showTableData(db, DiabecoContract.RegistroComida.TABLE_NAME);
	}

	public void showDetalleComida() {
		SQLiteDatabase db = this.getReadableDatabase();
		this.showTableData(db, DiabecoContract.RegistroDetalleComida.TABLE_NAME);
	}

	public void showVerticesGeocerca() {
		SQLiteDatabase db = this.getReadableDatabase();
		this.showTableData(db, DiabecoContract.VerticeGeocerca.TABLE_NAME);
	}

}
